/** * Created by admin on 2017/7/10 0010. */
<script type="text/javascript">
	/*
	 * 链接--例子
	 *	:href="bindLink('TaskWrite', [item.taskReportedId, item.taskCataId],[{index: item.taskReportedId,id: item.taskCataId}])"
	 *	返回：href = '/TaskWrite/1711818/1/?index=1711818&id:1'
	 */
	function bindLink(path, params, query) {
		let pathHead = '/' + path + '/';

		//判断params参数是否为空
		if(params != undefined && params.length != 0) {
			for(let i = 0; i < params.length; i++) {
				if(params[i] == null && params[i] == undefined) {
					if(i < params.length) {
						continue;
					} else {
						return pathHead;
					}
				} else {
					pathHead = pathHead + params[i] + '/';

					if(i + 1 == params.length && query == undefined) {
						return pathHead;
					} else if(i + 1 >= params.length && query.length != 0) {
						let queryStr = JSON.stringify(query[0]).replace(/{/, '?').replace(/,/, '&').replace(/:/g, '=').replace(/"/g, '').replace(/}/, '');
						return pathHead + queryStr;
					}
				}
			}
		} else {
			return pathHead;
		}

	}

	/*
	 * 计算剩余时间
	 */
	function timeRemaining(end) {
		//计算时间
		let currTime = new Date().getTime(), //当前时间
			endTime = new Date(end).getTime(); //结束时间
		if(end != null && endTime >= currTime) {
			let remaining = endTime - currTime,
				h = Math.floor(remaining / (3600 * 1000)), //时
				min = Math.floor((remaining % (3600 * 1000)) / (60 * 1000)); //分
			return h + '时' + min + '分'
		} else {
			return "已过期"
		}
	}

	/*
	 * 截取时间 10位
	 */
	function issueTimeSub(time) {
		return time.substring(0, 16);
	}

	/*
	 * 时间格式转换和截取
	 */
	function timeChange(date) {
		let d = new Date(date);
		return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate(); //2022-02-02
		//return d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();//2022-02-02 09:00:00
	}

	/*
	 * 暂无数据
	 */
	function isNull(arg) {
		return !arg ? '暂无' : arg;
	}

	/*
	 * 获得当前时间--格式：2017-07-27 16:32:18
	 */
	function getTime() {
		let date = new Date();
		let seperator1 = "-";
		let seperator2 = ":";
		let month = date.getMonth() + 1;
		let strDate = date.getDate();
		if(month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if(strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
			" " + date.getHours() + seperator2 + date.getMinutes() +
			seperator2 + date.getSeconds();
		return currentdate;
	}

	/*
	 * 判断涨跌值幅度
	 */
	function priceWave(obj) {
			var config = obj.waveConfg;
			var result = (obj.price*100 - obj.priorPrice*100)/100;
			if(result.toString().indexOf(".") > -1){
				var wave = result.toString().substr(0,result.toString().indexOf(".") + 3);
			} else {
				var wave = result.toString();
			}
//			if(result >= 0) {
//				return result.toString().substr(0,result.toString().indexOf(".") + 3);		
//				wave = Math.floor((obj.price - obj.priorPrice) * 100) / 100;
//			} else {
//				wave = Math.ceil((obj.price - obj.priorPrice) * 100) / 100;
//			}
			if(wave >= 0) {
				if(wave >= config.valueRise && config.valueRise !== "" && config.valueRise !== null && config.valueRise !== 0) {
					obj.err = 1;
					return true;
				} else if(wave >= config.waveValueRise && config.waveValueRise != "" && config.waveValueRise != null && config.waveValueRise !== 0) {
					obj.err = 1;
					return true;

				} else {
					obj.err = 0;
					return false;
				}
			} else {
				if(Math.abs(wave) >= config.valueFall && config.valueFall != "" && config.valueFall != null && config.valueFall !== 0) {
					obj.err = 1;
					return true;
				} else if(Math.abs(wave) >= config.waveValueFall && config.waveValueFall != "" && config.waveValueFall != null && config.waveValueFall !== 0) {
					obj.err = 1;
					return true;
				} else {
					obj.err = 0;
					return false;
				}
			}
		}
		/*
		 * 判断涨跌幅幅度
		 */
		function PriceRate(obj) {
			var config = obj.waveConfg;
//			var result = ((obj.price - obj.priorPrice) / obj.priorPrice)*100;
			var result = ((obj.price*100 - obj.priorPrice*100) / (obj.priorPrice*100))*100;
			if(result.toString().indexOf(".") > -1){
				var Rate = result.toString().substr(0,result.toString().indexOf(".") + 3);
			} else {
				var Rate = result.toString();
			}
//			if(result >= 0) {
//				Rate = Math.floor(((obj.price - obj.priorPrice) / obj.priorPrice) * 10000) / 100;
//			} else {
//				Rate = Math.ceil(((obj.price - obj.priorPrice) / obj.priorPrice) * 10000) / 100;

			if(Rate >= 0) {
				if(Rate >= config.rangeRise && config.rangeRise != "" && config.rangeRise != null && config.rangeRise !== 0) {
					obj.err = 2;
					return true;
				} else if(Rate >= config.waveRangeRise && config.waveRangeRise != "" && config.waveRangeRise != null && config.waveRangeRise !== 0) {
					obj.err = 2;
					return true;
				} else {
					obj.err = 0;
					return false;
				}
			} else {
				if(Math.abs(Rate) >= config.rangeFall && config.rangeFall != "" && config.rangeFall != null && config.rangeFall != 0) {
					obj.err = 2;
					return true;
				} else if(Math.abs(Rate) >= config.waveRangeFall && config.waveRangeFall !== "" && config.waveRangeFall !== null && config.waveRangeFall !== 0) {
					obj.err = 2;
					return true;
				} else {
					obj.err = 0;
					return false;
				}
			}
		}
		/*
		 * 判断多期未变
		 */
		function issue(obj) {
			var config = obj.waveConfg;
			if(obj.priorPrice == obj.price) {
				if(obj.noChangeTimes !== "" && obj.noChangeTimes !== null && config.issue !== 0 && config.issue !== "" && config.issue !== null){
					obj.localnct = obj.noChangeTimes + 1;
					if(obj.localnct >= config.issue) {
						obj.err = 3;
						return true;
					} else {
						obj.err = 0;
						return false;
					}
				}
			} else {
				obj.localnct = 1;
				obj.err = 0;
				return false;
			}
		}
		/*
		 * 获取附件内容
		 */
		function getFileDetails(url){
			/*
			 * 参数url来的数据
			 * /framework/upload/downFileapp.do?id=c99d63c9-7605-42da-8f51-920099a8fe07&businessId=217609&dirName=messagearticle
			 *
			 * 改成以下链接
			 *
			 * /framework/upload/downFile.do?id=c99d63c9-7605-42da-8f51-920099a8fe07%26businessId=217609%26dirname=messagearticle&id=c99d63c9-7605-42da-8f51-920099a8fe07&businessId=217609&dirName=messagearticle
			 * */
			let link = '';
			let index = url.indexOf("?"),  //获取问号的位置
					before = url.substr(0,index),  //问号前面的路径
					after = url.substr(index + 1), //问号后面的内容
					Jmiddle = after.replace(/&/g, '%26'),  //拼接的中间
					Jafter = after.replace(/dirname/g, 'dirName');  //拼接的末尾

			link = this.$ajax.fileUrl + before + '?' + Jmiddle + '&' + Jafter;
			this.$store.commit('getFileLink', link);
		}

		/*
		 * 空链接
		 */
		function noLink(name){
			/*
			 * 参数url来的数据
			 * /framework/upload/downFileapp.do?id=c99d63c9-7605-42da-8f51-920099a8fe07&businessId=217609&dirName=messagearticle
			 *
			 * 改成以下链接
			 *
			 * /framework/upload/downFile.do?id=c99d63c9-7605-42da-8f51-920099a8fe07%26businessId=217609%26dirname=messagearticle&id=c99d63c9-7605-42da-8f51-920099a8fe07&businessId=217609&dirName=messagearticle
			 * */
			let nameIndex = name.indexOf("."),
					suffix = name.substr(nameIndex + 1)

			if(suffix == 'tif'){
				return '#';
			}else{
				return '/fileDetails/';
			}
		}

		export default {
			bindLink,
			timeRemaining,
			issueTimeSub,
			timeChange,
			isNull,
			getTime,
			priceWave,
			PriceRate,
			issue,
			getFileDetails,
			noLink
		}
</script>
